package com.ll.cpu;

/**
 * @author 刘龙
 * @version 1.0
 * main线程启动两个子线程
 */
public class Thread03 {
    public static void main(String[] args) {
        T1 t1 = new T1();
        T2 t2 = new T2();
        Thread thread1 = new Thread(t1);
        Thread thread2 = new Thread(t1);

        //启动第一个线程
        thread1.start();

        //启动第二个线程
        thread2.start();
    }
}

class T1 implements Runnable {
    private int count = 0;

    @Override
    public void run() {
        while (true) {
            //每个一秒输出hello,输出10次退出
            System.out.println("hello " + (++count) + ",线程:" + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            // 退出条件
            if (count == 60) {
                break;
            }
        }
    }
}

class T2 implements Runnable {

    private int count = 0;

    @Override
    public void run() {
        while (true) {
            //每个一秒输出hello,输出10次退出
            System.out.println("hi " + (++count) + ",线程:" + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            // 退出条件
            if (count == 50) {
                break;
            }
        }
    }
}
